## 给图片和标签文件统一加前缀
import os

def add_prefix_to_filenames(folder_path, prefix):
    # 定义需要处理的子文件夹名称
    subfolders = ['Annotations', 'JPEGImages']

    for subfolder in subfolders:
        subfolder_path = os.path.join(folder_path, subfolder)
        
        # 检查子文件夹是否存在
        if not os.path.exists(subfolder_path):
            print(f"子文件夹 {subfolder} 不存在，跳过。")
            continue

        # 遍历子文件夹中的所有文件
        for filename in os.listdir(subfolder_path):
            old_file_path = os.path.join(subfolder_path, filename)
            
            # 检查是否是文件（避免处理文件夹）
            if os.path.isfile(old_file_path):
                new_filename = prefix + filename
                new_file_path = os.path.join(subfolder_path, new_filename)
                
                # 重命名文件
                os.rename(old_file_path, new_file_path)
                # print(f"已重命名: {old_file_path} -> {new_file_path}")

if __name__ == "__main__":
    # 输入文件夹路径和前缀
    folder_path = "/home/shuai/Documents/mydataset/my_usv_aug/BACKGROUND-Seaships"
    prefix = "s_"

    add_prefix_to_filenames(folder_path, prefix)
